package view.commonview;

import java.awt.BorderLayout;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JFrame;

import view.UtilityConstants;

import controller.commoncontroller.ExitListener;
import controller.commoncontroller.UtilityDialogs;
import model.editormodel.EditorModel;
import model.simulationmodel.SimulationModel;

/**
 * <b>Erbt:</b> <code>JFrame</code> <br>
 * <b>In Verbindung stehende Klassen:</b> <code>CircuitTypeArea, InfoPanel,
 * MenuBar, TabbedPane, ToolBar</code><br>
 * <b>Funktion:</b> Darstellung des Programmframes <br>
 * <br>
 * Diese Klasse dient zur Darstellung des Programmfensters.
 * 
 * @author Team Locsi
 * 
 */
@SuppressWarnings("serial")
public class LocsiFrame extends JFrame {
	
	/*
	 * Referenzen auf andere View-Objekte
	 */
	private MenuBar menuBar;
	private ToolBar tools;
	private CircuitTypeArea cta;
	private TabbedPane tabs;
	private InfoPanel info;

	/**
	 * Dieser Konstruktur erzeugt das Programmfenster mit folgenden
	 * Viewelementen: <code>TabbedPane</code>, <code>MenuBar</code>,
	 * <code>ToolBar</code>, <code>CircuitTypeArea</code> und
	 * <code>InfoPanel</code>.
	 * 
	 * @param eModel
	 *            <code>EditorModel</code> - Referenz auf
	 *            <code>EditorModel</code>
	 * @param sModel
	 *            <code>SimulationModel</code> - Referenz auf das
	 *            <code>SimulationModel</code>
	 */
	public LocsiFrame(EditorModel eModel, SimulationModel sModel) {
		this.assignIcon();
		UtilityDialogs.setMyFrame(this);
		ExitListener exitListener = new ExitListener(eModel);
		this.addWindowListener(exitListener);
		this.info = new InfoPanel(eModel);
		this.cta = new CircuitTypeArea();
		this.tools = new ToolBar();
		this.tabs = new TabbedPane(eModel, sModel, this.cta, this.tools,
				this.info);
		this.tools.setTabbedPane(tabs);
		this.menuBar = new MenuBar(eModel, sModel, this.tabs,
				this.info.getInfoArea(), exitListener);
		this.tabs.setMenuBar(eModel, sModel, menuBar);
		this.setPreferredSize(new Dimension(1024, 768));
		this.setMinimumSize(new Dimension(1024, 768));
		this.setLayout(new BorderLayout());
		this.add(this.tools, BorderLayout.EAST);
		this.add(this.cta, BorderLayout.NORTH);
		this.add(this.tabs, BorderLayout.CENTER);
		this.add(this.info, BorderLayout.SOUTH);
		this.setJMenuBar(this.menuBar);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.setVisible(true);
		this.setTitle("LOCSI - Logical Circuit Simulator");
		this.setLocationRelativeTo(null);
		this.pack();
	}

	/**
	 * Diese Methode setzt das Programmicon
	 */
	private void assignIcon() {
		Image image = Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource(
				UtilityConstants.ICON_PATH + "locsiLogtransp.png"));
		setIconImage(image);
	}

	/**
	 * Diese Methode gibt das <code>TabbedPane</code> zurueck.
	 * 
	 * @return <code>TabbedPane</code> - das <code>TabbedPane</code>
	 */
	public TabbedPane getTabs() {
		return tabs;
	}
}